{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6baec9a7",
   "metadata": {},
   "source": [
    "### Description of SV call set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c720fdfd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "from pathlib import Path \n",
    "import pysam "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "33f0d366",
   "metadata": {},
   "outputs": [],
   "source": [
    "sv_info_path = \"/lustre/scratch126/humgen/projects/interval_rna/interval_rna_seq/thomasVDS/lof_missense/data/sv_vcf/info_table/final_sites_critical_info_allele.txt\"\n",
    "sv_info_df = pd.read_csv(sv_info_path, sep=\"\\t\", dtype={\"plinkID\":str})\n",
    "vcf_path = \"/lustre/scratch126/humgen/projects/interval_rna/interval_rna_seq/thomasVDS/lof_missense/data/sv_vcf/filtered_merged_gs_svp_10728.vcf.gz\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5b5806c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of SV calls: 123801\n",
      "Number of DEL calls: 107966\n",
      "Number of MEI calls: 1395\n",
      "Number of DUP calls: 11681\n",
      "Number of INV calls: 2759\n"
     ]
    }
   ],
   "source": [
    "# total number of SVs \n",
    "sv_plink_ids = sv_info_df.plinkID.unique()\n",
    "print(f\"Number of SV calls: {len(sv_plink_ids)}\")\n",
    "for sv_type in sv_info_df.SVTYPE.unique(): \n",
    "    sv_plink_ids_by_type = sv_info_df[sv_info_df.SVTYPE == sv_type].plinkID.unique()\n",
    "    print(f\"Number of {sv_type} calls: {len(sv_plink_ids_by_type)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d2194828",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "VCF loaded.\n",
      "Subset VCF to samples with RNA-seq ...\n",
      "Number of samples in VCF: 10728\n"
     ]
    }
   ],
   "source": [
    "# number of samples with SV calls \n",
    "vcf = pysam.VariantFile(vcf_path, mode = \"r\")\n",
    "print(\"VCF loaded.\")\n",
    "print(\"Subset VCF to samples with RNA-seq ...\")\n",
    "vcf_samples = [sample for sample in vcf.header.samples]\n",
    "print(f\"Number of samples in VCF: {len(vcf_samples)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08cabf40",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
